//Define an external unit to write the log macro,namely@"ReaderOTR2000DLL_WinCE.dll"
//#define EXTERN_LOG
//#define WINCED

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ReaderOTR2000Demo
{
    public class ReaderOTR2000API
    {
        /// <summary>
        /// Define constants
        /// </summary>
        //public const string PUBLIC_Reader2300DLL_PATH = @"Reader2300DLL.dll";
#if WINCED
        public const string PUBLIC_ReaderOTR2000DLL_PATH = @"ReaderOTR2000DLL-H100Demo.dll";//Handheld devices used
#else
        public const string PUBLIC_ReaderOTR2000DLL_PATH = @"ReaderDynamicLib.dll";//PC Equipment used
#endif





        [StructLayout(LayoutKind.Sequential)]
        public struct ReaderDate
        {
            public byte Year;			//Years
            public byte Month;			//month
            public byte Day;			//Day
            public byte Hour;			//Hour
            public byte Minute;			//Minute
            public byte Second;			//Second
        }

        //public struct Reader1200Param
        //{
        //    public byte BaudRate;			//Serial communication speed，Value:00H~08H，Represent rate with the "Set Baud Rate" command.
        //    public byte Power;			//Transmission power value，Value:30~160.
        //    public byte Min_Frequence;		//Transmit microwave signal frequency starting point，value: 1~63.
        //    public byte Max_Frequence;		//Transmit microwave signal frequency Termination Point，value: 1~63.
        //    public byte Reserve5;			//Retention
        //    public byte WorkMode;			//Reader works method: 0 - Active mode，1 - Command mode
        //    public byte Reserve7;			//Retention
        //    public byte NumofCard;			//Maximum number of tag read.
        //    public byte TagType;			//Types of Tags：01H - ISO18000-6B，02H - EPCC1，04H - EPCC1G2，08H - EM4442.
        //    public byte ReadDuration;			//Duration of reading tag：RF emitting duration time ，Valid only for EM labels；0－10ms，1－20ms，2－30ms，3－40ms.
        //    public byte ReadTimes;			//times of reading tag M:receivedHost reading command，Reader execute this command M times.
        //    public byte Reserve12;			//Retention
        //    public byte Reserve13;			//Retention
        //    public byte Reserve14;			//Retention
        //    public byte Reserve15;			//Retention
        //    public byte Reserve16;			//Retention
        //    public byte Reserve17;			//Retention
        //    public byte Reserve18;			//Retention
        //    public byte Reserve19;			//Retention
        //    public byte Reserve20;			//Retention
        //    public byte EnableBuzzer;			//Retention
        //    public byte Reserve22;			//Retention
        //    public byte Reserve23;			//Retention
        //    public byte Reserve24;			//Retention
        //    public byte Reserve25;			//Retention
        //    public byte Reserve26;			//Retention
        //    public byte Reserve27;			//Retention
        //    public byte Reserve28;			//Retention
        //    public byte Reserve29;			//Retention
        //    public byte Reserve30;			//Retention
        //    public byte Reserve31;			//Retention
        //    public byte Reserve32;			//Retention
        //}

        public struct ReaderOTR2000Param
        {
            public byte BaudRate;			//the communicate speed of serial port, set value:00H-08H, represent speed is same as the command of "set baud rate"
            public byte Power;				//the value of transmit powr, set the value:30-160.
            public byte Min_Frequence;			//the start point of transmit microwave signal frequence,set value:1~63.
            public byte Antenna;			//select antenna. 1 - ant1, 2 - ant2, 4 - ant4, 8 - ant8
            public byte WorkMode;			//reader WorkMode: 1 - timing mode, 2 - trigger mode, 3 - command mode, 4 - timing mode2, 5 - trigger mode2
            public byte ReadInterval;			//interval of reading. 0-10ms, 1-30ms, 2-50ms
            public byte OutMode;			//card number output mode(direct output, standard output)
            public byte TriggerMode;			//trigger mode
            public byte IDPosition;			//the storage address of card number in electron tag
            public byte IfTestValidity;			//if tag is legal 
            public byte OutInterface;			//card number output interface and format(Wiegan26,Wiegan34,RS485,RS232,RJ45).
            public byte NumofCard;			//the maximum quantity of reading card
            public byte Power2;				//transimit power 2, set value:30~160.
            public byte TagType;			//types of tag: 01H - ISO18000-6B，02H - EPCC1，04H - EPCC1G2，08H - EM4442.
            public byte WiegandWidth;			//Weigand impulse width value
            public byte WiegandInterval;		//Weigand impulse interval value
            public byte ID_Start;			//outpuit start bit of card number,set value:0~4.
            public byte Max_Frequence;			//the ending point of transmit microwave frequence,set value: 1~63.
            public byte ReadDuration;			//the duration of reading card: the duration of RF transmit,only availiable to EM tag: 0-10ms，1-20ms，2-30ms，3-40ms.
            public byte Reserve20;			//reserve 
            public byte Reserve21;			//reserve
            public byte Reserve22;			//reserve
            public byte Reserve23;			//reserve
            public byte Reserve24;			//reserve
            public byte Reserve25;			//reserve
            public byte Reserve26;			//reserve
            public byte Reserve27;			//reserve
            public byte Reserve28;			//reserve
            public byte Reserve29;			//reserve
            public byte Reserve30;			//reserve
            public byte TX_Mode;			//transmit mode: 0 - receive receive and send mode; 1 - transmit mode
            public byte Reserve32;			//reserve

        }

        //reader active operating parameters
        public struct Reader1200AutoParam
        {
            public byte AutoMode;		//mode of reading tag：0 - Timing mode，1 - Trigger mode
            public byte TimeH;			//Label retention time：Unit：Seconds. The default value is 1
            public byte TimeL;			//
            public byte Interval;		//0 - 10ms，1 - 20ms，2 - 30ms，3 - 50ms，4 - 100ms. The default value is 2actively read tag one time at every set time
            public byte NumH;			//Tag number reserved: The default value is 1. The number of the tag ID read keep in reader memory. 
            public byte NumL;			//
            public byte OutputManner;		//Data Output Format: 0 - Simplified format，1 - Standard Format，2 - XML Format. The default value is 0.
            public byte OutInterface;		//Output Interface: 0 - RS232 interface，1 - RS485 interface，2 - RJ45 interface. The default value is 0.
            public byte Mask1;			//informed host mask
            public byte Mask2;			//
            public byte Mask3;			//
            public byte Mask4;			//
            public byte Report_Interval;	//Notification interval: Unit second.Default value is 1. actively inform host a time At intervals of set time.
            public byte Report_Condition;	//Notification condition: The default value is 1. 0 - Passive notification，1 - Timing notification，2 - Add new tag，3 - reduce tag，4 - Changes in the number of tags
            public byte Report_Output;		//Notification output
            public byte Antenna;		//Antenna selection. 1-ant1,2-ant2,4-ant4,8-ant8
            public byte TriggerMode;		//Trigger method.
            public byte HostIP1;		//Notified IP address
            public byte HostIP2;		//
            public byte HostIP3;		//
            public byte HostIP4;		//
            public byte Port1;			//notified port
            public byte Port2;			//
            public byte HostMAC1;		//notified MAC
            public byte HostMAC2;		//
            public byte HostMAC3;		//
            public byte HostMAC4;		//
            public byte HostMAC5;		//
            public byte HostMAC6;		//
            public byte Alarm;			//0 - No alarm，1 - alarm.Under timing and trigger modes, whether test to alarm.
            public byte Gateway1;		//Notified Gateway address
            public byte Gateway2;		//
            public byte Gateway3;		//
            public byte Gateway4;		//
        }



        #region Controlling command
        //Connect the reader
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int ConnectScanner(ref int hScanner, string PortNum, int nBaudRate);

        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_ConnectScanner(ref int hSocket, string nTargetAddress, uint nTargetPort, string nHostAddress, uint nHostPort);
        
        //Disconnect the reader
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int DisconnectScanner(int hScanner);

        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_DisconnectScanner(int hSocket);
        
        //Get the reader version number       
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int GetReaderVersion(int hScanner, ref int hardver, ref int Softver);

        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_GetReaderVersion(int hSocket, ref int hardver, ref int Softver);
        
        //Select Work antenna       
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int SetAntenna(int hScanner, int m_antenna_sel);

        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_SetAntenna(int hSocket, int m_antenna_sel);

        //set reader's relay state
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int SetRelay(int hScanner, int Relay);

        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_SetRelay(int hSocket, int Relay);

        //Set the output power
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int SetOutputPower(int hScanner, int nPower1);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_SetOutputPower(int hSocket, int nPower1);


        //Read the operating parameters of the reader
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int ReadParam(int hScanner, ref ReaderOTR2000Param pParam);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_ReadParam(int hSocket, ref ReaderOTR2000Param pParam);

        //Set operating parameters of reader
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int WriteParam(int hScanner, ref ReaderOTR2000Param pParam);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_WriteParam(int hSocket, ref ReaderOTR2000Param pParam, byte[] Password);


        //Get active operating parameters
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int GetAutoParameters(int hScanner, ref Reader1200AutoParam pParam);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_GetAutoParameters(int hSocket, ref Reader1200AutoParam pParam);

        //Set active operating parameters
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int SetAutoParameters(int hScanner, ref Reader1200AutoParam pParam, byte[] Password);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_SetAutoParameters(int hSocket, ref  Reader1200AutoParam pParam, byte[] Password);

        //Read reader's factory parameters
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int ReadFactoryParameter(int hScanner);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_ReadFactoryParameter(int hSocket);

        //Reset reader
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int Reboot(int hScanner);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_Reboot(int hSocket);
        
        //Set the time
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int SetReaderTime(int hScanner, ReaderDate time);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_SetReaderTime(int hSocket, ReaderDate time);

        //Get time
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int GetReaderTime(int hScanner, ref ReaderDate time);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_GetReaderTime(int hSocket, ref ReaderDate time);


        //Get reader ID
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int GetReaderID(int hScanner, byte[] ReaderID);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_GetReaderID(int hSocket, byte[] ReaderID);

        //Set tag filter
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int SetReportFilter(int hScanner, int ptr, int len, byte[] Mask);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_SetReportFilter(int hSocket, int ptr, int len, byte[] Mask);

        //Get Tag Filter
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int GetReportFilter(int hScanner, ref int ptr, ref int len, byte[] Mask);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_GetReportFilter(int hSocket, ref int ptr, ref int len, byte[] Mask);

        //Stop reader's auto
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int StopAuto(int hScanner);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_StopAuto(int hSocket);

        //Automatic mode
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int AutoMode(int hScanner, int Mode);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_AutoMode(int hSocket, int Mode);

        //==============================Network commands==============================
        //Set the IP address of the reader
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int SetNetwork(int hScanner, byte[] IP_Address, int Port, byte[] Mask, byte[] Gateway);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_SetNetwork(int hSocket, byte[] IP_Address, int Port, byte[] Mask, byte[] Gateway);

        //Get reader IP address
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int GetNetwork(int hScanner, byte[] IP_Address, ref int Port, byte[] Mask, byte[] Gateway);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_GetNetwork(int hSocket, byte[] IP_Address, ref int Port, byte[] Mask, byte[] Gateway);

        //Set the MAC address of the reader
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int SetReaderMAC(int hScanner, byte[] MAC);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_SetReaderMAC(int hSocket, byte[] MAC);

        //Get reader MAC address
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int GetReaderMAC(int hScanner, byte[] MAC);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_GetReaderMAC(int hSocket, byte[] MAC);
        #endregion

        #region EPCC1G2
        //==============================EPCC1G2Data read and write commands==============================
        //Identified Tag's EPC

        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_ReadLabelID(int hScanner, int mem, int ptr, int len, byte[] mask, byte[] IDBuffer, ref int nCounter);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_ReadLabelID(int hSocket, int mem, int ptr, int len, byte[] mask, byte[] IDBuffer, ref int nCounter);
        
        //Reading a Data
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_ReadWordBlock(int hScanner, byte EPC_WORD, byte[] IDBuffer, byte mem, byte ptr, byte len, byte[] Data, byte[] AccessPassword);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_ReadWordBlock(int hSocket, byte EPC_WORD, byte[] IDBuffer, byte mem, byte ptr, byte len, byte[] Data, byte[] AccessPassword);

        //Write a data
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_WriteWordBlock(int hScanner, byte EPC_WORD, byte[] IDBuffer, byte mem, byte ptr, byte len, byte[] Data, byte[] AccessPassword);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_WriteWordBlock(int hSocket, byte EPC_WORD, byte[] IDBuffer, byte mem, byte ptr, byte len, byte[] Data, byte[] AccessPassword);
        
        //set R/W protection status
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_SetLock(int hScanner, byte EPC_WORD, byte[] IDBuffer, byte mem, byte Lock, byte[] AccessPassword);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_SetLock(int hSocket, byte EPC_WORD, byte[] IDBuffer, byte mem, byte Lock, byte[] AccessPassword);
        
        //Erase tag data
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_EraseBlock(int hScanner, byte EPC_WORD, byte[] IDBuffer, byte mem, byte ptr, byte len);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_EraseBlock(int hSocket, byte EPC_WORD, byte[] IDBuffer, byte mem, byte ptr, byte len);
        
        //Kill tag
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_KillTag(int hScanner, byte EPC_WORD, byte[] IDBuffer, byte[] KillPassword);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_KillTag(int hSocket, byte EPC_WORD, byte[] IDBuffer, byte[] KillPassword);
        
        //Write EPC
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_WriteEPC(int hScanner, byte len, byte[] Data, byte[] AccessPassword);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_WriteEPC(int hSocket, byte len, byte[] Data, byte[] AccessPassword);
        
        //Block Lock command
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_BlockLock(int hScanner, byte EPC_WORD, byte[] IDBuffer, byte ptr, byte[] AccessPassword);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int NetEPC1G2_BlockLock(int hSocket, byte EPC_WORD, byte[] IDBuffer, byte ptr, byte[] AccessPassword);
        
        //EAS Operation Command
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_ChangeEas(int hScanner, byte EPC_WORD, byte[] IDBuffer, byte State, byte[] AccessPassword);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_ChangeEas(int hSocket, byte EPC_WORD, byte[] IDBuffer, byte State, byte[] AccessPassword);

        //EAS Alarm command
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_EasAlarm(int hScanner);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_EasAlarm(int hSocket);

        //Read protection setting
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_ReadProtect(int hScanner, byte[] AccessPassword, byte EPC_WORD, byte[] IDBuffer);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_ReadProtect(int hSocket, byte[] AccessPassword, byte EPC_WORD, byte[] IDBuffer);

        //Reset read protection setting
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_RStreadProtect(int hScanner, byte[] AccessPassword);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_RStreadProtect(int hSocket, byte[] AccessPassword);

        //Detect tag
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int EPC1G2_DetectTag(int hScanner);
        //[DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        //public static extern int Net_EPC1G2_DetectTag(int hSocket);

        #endregion



        #region ISO6B
        //==============================ISO6B Data read and write commands==============================
        //Identify tag's EPC
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int ISO6B_ReadLabelID(int hScanner, byte[,] IDBuffer, ref int nCounter);

        //Reading a Data
        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int ISO6B_ReadByteBlock(int hScanner, byte[] IDBuffer, byte ptr, byte len, byte[] Data);

        [DllImport(PUBLIC_ReaderOTR2000DLL_PATH)]
        public static extern int ISO6B_WriteByteBlock(int hScanner, byte[] IDBuffer, byte ptr, byte len, byte[] Data);

        #endregion




        #region systemAPI
        public delegate void TimerProc(IntPtr hWnder, uint nMsg, int nIDEvent, int dwTime);
#if WINCED
        [DllImport("coredll.dll")]
#else
        [DllImport("user32.dll")]
#endif
            public static extern int SetTimer(int hwnd, int nIDEvent, int uElapse, TimerProc CB);
#if WINCED
        [DllImport("coredll.dll")]
#else
        [DllImport("user32.dll")]
#endif
        public static extern int KillTimer(int hwnd, int nIDEvent);

#if WINCED
        [DllImport("coredll.dll")]
#else
        [DllImport("kernel32.dll")]
#endif
        public static extern bool GetCommState(
         int hFile,
         ref DCB lpDCB
       );

#if WINCED
        [DllImport("coredll.dll")]
#else
        [DllImport("kernel32.dll")]
#endif
        public static extern bool SetCommState(
         int hFile,  // Communication device handle 
         ref DCB lpDCB    // Device Control Block 
       );

#if WINCED
        [DllImport("coredll.dll")]
#else
        [DllImport("kernel32.dll")]
#endif
        public static extern bool PurgeComm(
        int hFile,  // Communication device handle
        uint dwFlags
        );


//        [DllImport("kernel32.dll")]
//        public static extern bool Beep(int frequency, int duration);

#if WINCED
        [DllImport("coredll.dll")]
#else
        [DllImport("user32.dll")]
#endif
        public static extern bool MessageBeep(int beepType);


        [StructLayout(LayoutKind.Sequential)]
        public struct DCB
        {
            //taken from c struct in platform sdk  
            public int DCBlength;	// sizeof(DCB)  
            public int BaudRate;	// Specifies the current baud rate current baud rate 
            				// these are the c struct bit fields, bit twiddle flag to set 
            public int fBinary;		// Specifies whether to allow binary mode, underwindows95,must be host TRUE binary mode, no EOF check  
            public int fParity;		// Specify whether to allow the parity enable parity checking  
            public int fOutxCtsFlow;	// Specifies whether the CTS is used to detect transmission control，When it is TRUE, it is CTS, When it is off, Transmission will be suspended. CTS output flow control  
            public int fOutxDsrFlow;	// Specifies whether the CTS is used to detect transmission control DSR output flow control  
            public int fDtrControl;	// DTR_CONTROL_DISABLE value have DTR set OFF, DTR_CONTROL_ENABLE value have DTR set ON, DTR_CONTROL_HANDSHAKE Allow DTR "handshake" DTR flow control type  
            public int fDsrSensitivity;	// When value is TRUE, DSR is off, the received Bytes are ignored. DSR sensitivity  
            public int fTXContinueOnXoff;// Specify when the receive buffer is full, and the driver has been sent out XoffChar character transmission is stopped. TRUE, the receive buffer of bytes received XoffLim buffer is full and the driver has been sent out XoffChar receive byte character aborted after sending continue. FALSE, received on behalf of the receive buffer of bytes XonChar buffer is empty and the driver has been sent out resumes sending the XonChar after sending to proceed。XOFF continues Tx  
            public int fOutX;		// TRUE, then stops receiving the transmitted and received XoffChar XonChar after the start XON / XOFF out flow control 
            public int fInX;		// TRUE,  receive buffer, received mean after buffer full XoffLim, XoffChar sent out and receive buffer,  received mean buffer empty XonLim after, XonChar sent XON / XOFF in flow control
            public int fErrorChar;	// This value is TRUE and fParity is  TRUE,  with ErrorChar member to specify the character replace parity error's received character enable errorreplacement  
            public int fNull;		// TRUE，when received, remove empty (zero value) bytes enable null stripping  
            public int fRtsControl;	// RTS flow control 
		/*when RTS_CONTROL_DISABLE,RTS is set to OFF 
		when RTS_CONTROL_ENABLE, RTS is set to ON 
		when en RTS_CONTROL_HANDSHAKE, 
		When the receive buffer is less than half full, the RTS is ON
		When the receive buffer is more than three-quarters full, RTS is OFF
           	RTS_CONTROL_TOGGLE, 
           	When the receiving buffer still has remaining bytes RTS is ON, otherwise the default is OFF */
            public int fAbortOnError;	// TRUE,When an error occurs abort read and write operations, abort on error  
            public int fDummy2;		// Not used reserved  

            public uint flags;
            public ushort wReserved;	// Not used,must be 0 not currently used  
            public ushort XonLim;	// Before Specifying the XON character sending, receiving buffer can permit minimum number of bytes transmit XON threshold  
            public ushort XoffLim;	// Before Specifying the OXFF character sending, receiving buffer can permit minimum number of bytes transmit XOFF threshold  
            public byte ByteSize;	// Specifies the port is currently using data bits number of bits/byte, 4-8  
            public byte Parity;		// Specified port is currently using parity method , which may be:EVENPARITY,MARKPARITY,NOPARITY,ODDPARITY  0-4=no,odd,even,mark,space  
            public byte StopBits;	// Specified port is currently using Stop bits , which may be:ONESTOPBIT,ONE5STOPBITS,TWOSTOPBITS  0,1,2 = 1, 1.5, 2  
            public char XonChar;	// Specifies value used to send and receive the XON character Tx and Rx XON character  
            public char XoffChar;	// Specifies value used to send and receive the XOFF character Tx and Rx XOFF character  
            public char ErrorChar;	// This character is used to replace the receiving value when parity error occurs error replacement character  
            public char EofChar;	// When not using binary mode, the character is used to indicate the end of data end of input character  
            public char EvtChar;	// When this character is received, it will generate an event, received event character  
            public ushort wReserved1;	// not used reserved; do not use  
        }

        #endregion


    }
}
